home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PCMania 81
/
PCMania CD81_1.iso
/
PCMANIA
/
projue81
/
Borland
/
081pjw_1.c
next >
Wrap
C/C++ Source or Header
|
1999-05-30
|
6KB
|
257 lines
/****************************************************\
* 081PJW_1.C *
* Archivo con las funciones obligatorias *
* UN RELOJ *
* I±aki Otero. Villanueva de la Ca±ada, 1999. *
\****************************************************/
#define STRICT
#include "081PJW_1.H"
/*-------------------------- HANDLES Y VARIABLES ---*/
char Aplicacion[] = "RELOJ" ;
int iDate, iTime ;
char sDate[2], sTime[2], ampm[2][5] ;
/*--------------- FUNCION PRINCIPAL DEL PROGRAMA ---*/
#pragma argsused
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg ;
HWND hwnd ;
WNDCLASSEX wcx ;
wcx.cbSize= sizeof(WNDCLASSEX) ;
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = WinProc ;
wcx.cbClsExtra = 0 ;
wcx.cbWndExtra = 0 ;
wcx.hInstance = hInstance ;
wcx.hIcon = NULL ;
wcx.hCursor = LoadCursor(NULL, IDC_ARROW) ;
wcx.hbrBackground = (HBRUSH)
GetStockObject(LTGRAY_BRUSH);
wcx.lpszMenuName = NULL ;
wcx.lpszClassName = Aplicacion ;
wcx.hIconSm = NULL ;
if(!RegisterClassEx(&wcx)) return(FALSE) ;
hwnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
Aplicacion, Aplicacion,
WS_OVERLAPPEDWINDOW,
64, 64, 128, 128,
NULL, NULL, hInstance, NULL);
if(!hwnd) return(FALSE) ;
ShowWindow(hwnd, nCmdShow) ;
UpdateWindow(hwnd) ;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg) ;
DispatchMessage(&msg) ;
}
return(msg.wParam) ;
}
/*--------- FUNCION DEL PROCEDIMIENTO DE VENTANA ---*/
long CALLBACK WinProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
switch(message)
{
case WM_CREATE :
// Ponemos en marcha el cron≤metro
SetTimer(hwnd, 1, 1000, NULL) ;
// Tomamos los datos de Win.ini
TomarDatos() ;
// Pintamos el fondo de la ventana
SetClassLong(hwnd, GCL_HBRBACKGROUND,
GetSysColor(COLOR_3DFACE)) ;
return 0 ;
case WM_TIMER :
// Repintamos sobre la ventana sin borrarla
// para evitar parpadeos molestos
InvalidateRect (hwnd, NULL, FALSE) ;
return 0 ;
// Se ha modificado WIN.INI
case WM_WININICHANGE :
// Tomamos los datos de Win.ini
TomarDatos() ;
// Borramos el fondo de la ventana antes
// de repintar
InvalidateRect(hwnd, NULL, TRUE) ;
return 0 ;
// Repintado de la ventana
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps) ;
// Actualizamos el reloj
Actualizar(hdc) ;
EndPaint(hwnd, &ps) ;
return 0 ;
// Tomamos los datos de Win.ini
case WM_DESTROY:
// Destruimos el cron≤metro
KillTimer (hwnd, 1) ;
PostQuitMessage(0) ;
return 0 ;
default:
return DefWindowProc(hwnd, message,
wParam, lParam) ;
}
}
/*-------- FUNCION QUE TOMA LOS DATOS DE WIN.INI ---*/
void TomarDatos(void)
{
iDate = GetProfileInt("intl","iDate",0) ;
iTime = GetProfileInt("intl","iTime",0) ;
GetProfileString("intl","sDate","/",sDate,2) ;
GetProfileString("intl","sTime",":",sTime,2) ;
GetProfileString("intl","s1159","a.m.",ampm[0],5) ;
GetProfileString("intl","s2359","p.m.",ampm[1],5) ;
}
/*------ FUNCION QUE DIBUJA Y ACTUALIZA EL RELOJ ---*/
void Actualizar(HDC hdc)
{
char cCadena[64] ;
struct tm * datos ;
time_t ahora ;
// Tomamos datos
time(&ahora) ;
// Rellenamos la estructura
datos = localtime(&ahora) ;
// Rellenamos la cadena del mensaje datos de hora
if(iTime == 1)
{
wsprintf(cCadena, " %02d%s%02d%s%02d ",
(datos->tm_hour),
sTime, (datos->tm_min),
sTime, (datos->tm_sec)) ;
}
else
{
wsprintf(cCadena, " %d%s%02d%s%02d %s ",
((datos->tm_hour) % 12) ?
((datos->tm_hour) % 12) : 12,
sTime, (datos->tm_min),
sTime, (datos->tm_sec),
ampm[(datos->tm_hour) / 12]) ;
}
// Color del fondo
SetBkColor(hdc, GetSysColor(COLOR_3DFACE));
// Color del texto -> Rojo
SetTextColor(hdc, RGB(255, 0, 0)) ;
// Exhibimos el mensaje
TextOut(hdc, 25, 15, cCadena, strlen(cCadena)) ;
// Rellenamos la cadena del mensaje datos de fecha
wsprintf(cCadena, " %d%s%02d%s%02d ",
iDate == 1 ? (datos->tm_mday) :
iDate == 2 ? (datos->tm_year % 100) :
(datos->tm_mon + 1),
sDate,
iDate == 1 ? (datos->tm_mon + 1) :
iDate == 2 ? (datos->tm_mon + 1) :
(datos->tm_mday),
sDate,
iDate == 1 ? (datos->tm_year % 100) :
iDate == 2 ? (datos->tm_mday) :
(datos->tm_year % 100)) ;
// Exhibimos el mensaje
TextOut(hdc, 25, 40, cCadena, strlen(cCadena)) ;
// Dφa de la semana
switch(datos->tm_wday)
{
case 1:
strcpy(cCadena, " Lunes ") ;
break ;
case 2:
strcpy(cCadena, " Martes ") ;
break ;
case 3:
strcpy(cCadena, " MiΘrcoles ") ;
break ;
case 4:
strcpy(cCadena, " Jueves ") ;
break ;
case 5:
strcpy(cCadena, " Viernes ") ;
break ;
case 6:
strcpy(cCadena, " Sßbado ") ;
break ;
default:
strcpy(cCadena, " Domingo ") ;
break ;
}
// Exhibimos el mensaje
TextOut(hdc, 25, 65, cCadena, strlen(cCadena)) ;
}
/*------------------------------ FIN DEL ARCHIVO ---*/